package com.lplb.api.admin.service.impl.consumer;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lplb.api.admin.mapper.AdminAuthMapper;
import com.lplb.api.admin.model.dto.AdminAuthDTO;
import com.lplb.api.admin.model.entity.AdminAuth;
import com.lplb.api.admin.model.vo.AdminAuthVO;
import com.lplb.api.admin.service.consumer.UIAdminAuthService;
import com.lplb.common.core.result.R;
import com.lplb.common.core.service.BaseIServiceImpl;
import com.lplb.common.core.utils.BeanDtoVoUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 资源表 用户端服务接口实现
 * </p>
 *
 * @author ws
 * @date 2020-07-21
 */
@RestController
public class UAdminAuthServiceImpl  extends BaseIServiceImpl<AdminAuthMapper, AdminAuth> implements UIAdminAuthService {


         /**
         *  分页查询
         */
         @Override
         public R<IPage<AdminAuthVO>> findPage() {
             Page<AdminAuth> page = this.page(this.getPage(), new LambdaQueryWrapper<AdminAuth>()
                     .orderByAsc(AdminAuth::getCreateTime)
             );
             return R.success(BeanDtoVoUtil.pageVo(page, AdminAuthVO.class));
         }

        /**
        *  查询所有
        */
        @Override
        public R<List<AdminAuthVO>> findList() {
              List<AdminAuth> list = this.list(new LambdaQueryWrapper<AdminAuth>()
                      .orderByAsc(AdminAuth::getCreateTime)
              );
              return R.success(BeanDtoVoUtil.listVo(list, AdminAuthVO.class));
        }

        /**
        * ID 查询
        *
        * @return
        */
        @Override
        public R<AdminAuthVO> findId(@RequestParam String id) {
            AdminAuth adminAuth = this.getById(id);
            return R.success(BeanDtoVoUtil.convert(adminAuth,AdminAuthVO.class));
        }


        /**
        * 新增
        */
        @Override
        public R<Void> add(@RequestBody @Validated AdminAuthDTO dto) {
            this.save(dto.convert(AdminAuth.class));
            return R.success();
        }


        /**
        *  编辑
        */
        @Override
        public R<Void> upd(@RequestBody @Validated AdminAuthDTO dto) {
            this.updateById(dto.convert(AdminAuth.class));
            return R.success();
        }


        /**
        *  ID 删除
        */
        @Override
        public R<Void> removeId(@RequestParam String id) {
            this.removeById(id);
            return R.success();
        }

 }

